let BASE_URL = ""

if (process.env.NODE_ENV === 'development') {
	console.log("开发环境");
	BASE_URL = "https://growlaasia.com/"
} else {
	console.log("生产环境");
	BASE_URL = "https://growlaasia.com/"
}
var time = 0
export const httpRequest = options => {
	time++;
	uni.showLoading({
		title: "加载中",
		mask: true,
	});
	let headers = ""
	if (options.method == "POST") {
		headers = 'application/x-www-form-urlencoded'
	} else {
		headers = "application/json"
	}
	console.log(headers)
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || "GET", // 请求类型，默认为GET
			data: options.data || {}, // 请求参数，默认空对象
			header: {
				'content-type': headers //自定义请求头信息
			},
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({
					title: "请求失败！",
					icon: "none"
				})
				reject(err)
			},
			complete() {
				time--;
				if (time == 0) {
					uni.hideLoading()
				}
			}
		})
	})
}
